<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>客户账单 管理</title>
    <style type="text/css">
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div>
        <div id="pageInTab" class="pageInTab">
            <div tabid="cstBillTab" title="客户账单" lselected="true">
                <div class="searchArea">
                    <form id="searchBar">
                        <div class="fieldset1 clearFix">
                            <div class="fieldBox">
                                <div class="label">客户名称</div>
                                <div class="field">
                                    <input name="cstNm" id="cstNm" type="text" class="ui-textbox"
                                           validate="{required:true}" value="">
                                </div>
                            </div>
                            <div class="fieldBox">
                                <div class="label">客户ID</div>
                                <div class="field">
                                    <input name="cstId" id="cstId" type="text" class="ui-textbox"
                                           validate="{number:true}" value="">
                                </div>
                            </div>
                            <div class="formBtns notRight">
                                <span id="searchBtn" class="sq-button sq-button-round">查询</span>
                                <span id="clearBtn" class="sq-button sq-button-round">清空</span>
                                <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="fieldset1 tabel_col tabel_col_s clearFix">
                    <div class="sqPanel">
                        <div class="sqPanel_head inL">
                            <span>客户账单</span>
                        </div>
                        <div class="sqPanel_body">
                            <div id="billGrid" class="sq-grid"></div>
                        </div>
                    </div>
                </div>

                <%--挂靠公司账单查询框--%>
                <div class="searchArea">
                    <form id="searchBarLnkComp">
                        <div class="fieldset1 clearFix">
                            <div class="fieldBox">
                                <div class="label">挂靠公司名称</div>
                                <div class="field">
                                    <input name="lnkCompNm" id="lnkCompNm" type="text" class="ui-textbox"
                                           validate="{required:true}" value="">
                                </div>
                            </div>
                            <div class="fieldBox">
                                <div class="label">挂靠公司id</div>
                                <div class="field">
                                    <input name="lnkCompId" id="lnkCompId" type="text" class="ui-textbox"
                                           validate="{number:true}" value="">
                                </div>
                            </div>
                            <div class="formBtns notRight">
                                <span id="searchBtnLnkComp" class="sq-button sq-button-round">查询</span>
                                <span id="clearBtnLnkComp" class="sq-button sq-button-round">清空</span>
                                <input id="resetBtnLnkComp" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                            </div>
                        </div>
                    </form>
                </div>

            <%--挂靠公司账单--%>
                <div class="fieldset1 tabel_col tabel_col_s clearFix">
                    <div class="sqPanel">
                        <div class="sqPanel_head inL">
                            <span>挂靠公司账单</span>
                        </div>
                        <div class="sqPanel_body">
                            <div id="billGridLnkComp" class="sq-grid"></div>
                        </div>
                    </div>
                </div>
            </div>




            <div tabid="cstFundTab" title="客户来款">
                <iframe frameborder="0" name="cstFundInfo" id="cstFundInfo" src=""></iframe>
            </div>
            <div tabid="cstPayTab" title="客户支付表">
                <iframe frameborder="0" name="cstPayInfo" id="cstPayInfo" src=""></iframe>
            </div>
            <div tabid="cstOvdTab" title="支付表逾期明细">
                <iframe frameborder="0" name="cstOvdInfo" id="cstOvdInfo" src=""></iframe>
            </div>
            <div tabid="cstOvdHisTab" title="支付表逾期历史">
                <iframe frameborder="0" name="cstOvdHisInfo" id="cstOvdHisInfo" src=""></iframe>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    var billGrid = null, form = null, fundGrid = null, paySchGrid = null, mcrBillGrid = null, advPayGrid = null;
    var billGridLnkComp = null, formLnkComp = null;

    var pageInApp = {};
    var loadedTabs = [];
    $(function () {
        pageInTab = $("#pageInTab").ligerTab({
            height: 'auto',
            contextmenu: false,
            minIframeHeight: GET_minIframeHeight(),
            onAfterSelectTabItem: function (tabid) {
                if (loadedTabs.indexOf(tabid) < 0) {
                    loadedTabs.push(tabid);
                    if (tabid != "cstBillTab") {
                        switch (tabid) {
                            case "cstFundTab":
                                pageInTab.setTabItemSrc(tabid, "<%=path%>/risk/rentRemind/toCstFundPage.do");
                                break;
                            case "cstPayTab":
                                pageInTab.setTabItemSrc(tabid, "<%=path%>/risk/rentRemind/toCstPayPage.do");
                                break;
                            case "cstOvdTab":
                                pageInTab.setTabItemSrc(tabid, "<%=path%>/capital/capOverdueInfo/toCstOvdListPage.do");
                                break;
                            case "cstOvdHisTab":
                                pageInTab.setTabItemSrc(tabid, "<%=path%>/capital/capOverdueHis/toListPage.do");
                                break;
                        }
                    }
                }
                SetIframe_height();
            }
        });

        $.extend(true, pageInApp, {
            pageInTab: pageInTab
        });
        //客户账单
        billGrid = $("#billGrid").ligerGrid({
            url: '<%=path%>/risk/rentRemind/initCstBillList.do',
            method: 'get',
            columns: [
                {
                    display: '客户ID', name: 'cstId', minWidth: 100, align: 'left', enabledSort: false,
                    render: function (rowdata, rowindex, value) {
                        return '<a href="javascript:;" onclick="showCstDtl(' + rowdata.cstId + ')"><span class="gridTip" title="客户查看">' + rowdata.cstId + '</span></a>';
                    }
                },
                {display: '客户名称', name: 'cstNm', minWidth: 100, align: 'left', enabledSort: false},
                {display: '支付表号', name: 'paySchNo', width: 160, align: 'left', enabledSort: false},
                {display: '期次', name: 'payPd', width: 60, align: 'center', enabledSort: false},
                {display: '应还日期', name: 'payDt', width: 100, align: 'center', enabledSort: false, render: renderDate},
                {
                    display: '应还金额', name: 'ttlAmount', width: 100, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        if (rowdata.ttlAmount) {
                            return '&yen;' + FormatMoney(rowdata.ttlAmount / 100);
                        }
                    }
                },
                {display: '结清金额', name: 'settleAmt', width: 100, align: 'right', enabledSort: false,
                    render:function(rowdata,index,value){
                        if(rowdata.settleAmt){
                            return '&yen;'+FormatMoney(rowdata.settleAmt/100);
                        }else{
                            return '-';
                        }
                    }
                },
                {display: '剩余天数', name: 'remainDays', width: 80, align: 'center', enabledSort: false,
                    render:function(rowdata,index,value){
                        if(rowdata.isOverdue==1){
                            return '-'+rowdata.remainDays;
                        }
                        return rowdata.remainDays;
                    }
                },
                {
                    display: '是否逾期', name: 'isOverdue', width: 80, align: 'center', enabledSort: false,
                    render: function (rowdata, index, value) {
                        if (rowdata.isOverdue == 1) {
                            return '是';
                        } else {
                            return '否';
                        }
                    }
                },
                {display: '租赁期数', name: 'lsPd', width: 80, align: 'center', enabledSort: false},
                {display: '产品名称', name: 'prdNm', minWidth: 100, align: 'left', enabledSort: false},
                {display: '机构编码', name: 'insCode', minWidth: 100, align: 'left', enabledSort: false},
                {display: '扣款机构', name: 'isInsDeduct', width: 80, align: 'center', enabledSort: false,
                    render:function(rowdata,index,value){
                        if(rowdata.isInsDeduct==0){
                            return '我司';
                        }else if(rowdata.isInsDeduct==1){
                            return '浙商';
                        }
                    }
                },
                {display: '是否能够还款', name: 'repaymentFlag', width: 80, align: 'center', enabledSort: false,
                    render:function(rowdata,index,value){
                        if(rowdata.repaymentFlag==1){
                            return '是';
                        }else{
                            return '否';
                        }
                    }
                },
                {display: '是否担保还款账单', name: 'isGuarantee', width: 80, align: 'center', enabledSort: false,
                    render:function(rowdata,index,value){
                        if(rowdata.isGuarantee==1){
                            return '是';
                        }else{
                            return '否';
                        }
                    }
                },
            ],
            usePager: false,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '300',
            heightDiff: -2,
            allowUnSelectRow: true,
            alternatingRow: false,
            delayLoad: true,
            checkbox: false
        });

        billGrid.setHeight(100);


        form = $("#searchBar").ligerForm({
            validate: true
        });
        $("#pageloading").hide();

        /* 查询 */
        $("#searchBtn").click(function (event) {
            if (!form.valid()) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
                return false; //验证不通过，不执行以下代码
            }
            form = liger.get("searchBar");
            var data = form.getData();
            for (name in data) {
                billGrid.setParm(name, data[name]);
            }
            billGrid.reload();
        });

        /* 清空 */
        $("#clearBtn").click(function (event) {
            clearLigerForm("searchBar");
        });


        /**
         * 挂靠公司账单
         * @type {jQuery}
         */
        billGridLnkComp = $("#billGridLnkComp").ligerGrid({
            url: '<%=path%>/risk/rentRemind/initLnkCompCstBillList.do',
            method: 'get',
            columns: [
                {
                    display: '客户ID', name: 'cstId', minWidth: 100, align: 'left', enabledSort: false,
                    render: function (rowdata, rowindex, value) {
                        return '<a href="javascript:;" onclick="showCstDtl(' + rowdata.cstId + ')"><span class="gridTip" title="客户查看">' + rowdata.cstId + '</span></a>';
                    }
                },
                {display: '客户名称', name: 'cstNm', minWidth: 100, align: 'left', enabledSort: false},
                {display: '支付表号', name: 'paySchNo', width: 160, align: 'left', enabledSort: false},
                {display: '期次', name: 'payPd', width: 60, align: 'center', enabledSort: false},
                {display: '应还日期', name: 'payDt', width: 100, align: 'center', enabledSort: false, render: renderDate},
                {
                    display: '应还金额', name: 'ttlAmount', width: 100, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        if (rowdata.ttlAmount) {
                            return '&yen;' + FormatMoney(rowdata.ttlAmount / 100);
                        }
                    }
                },
                {
                    display: '剩余天数', name: 'remainDays', width: 80, align: 'center', enabledSort: false,
                    render: function (rowdata, index, value) {
                        if (rowdata.isOverdue == 1) {
                            return '-' + rowdata.remainDays;
                        }
                        return rowdata.remainDays;
                    }
                },
                {
                    display: '是否逾期', name: 'isOverdue', width: 80, align: 'center', enabledSort: false,
                    render: function (rowdata, index, value) {
                        if (rowdata.isOverdue == 1) {
                            return '是';
                        } else {
                            return '否';
                        }
                    }
                },
                {display: '租赁期数', name: 'lsPd', width: 80, align: 'center', enabledSort: false},
                {display: '产品名称', name: 'prdNm', minWidth: 100, align: 'left', enabledSort: false},
                {display: '机构编码', name: 'insCode', minWidth: 100, align: 'left', enabledSort: false},
                {display: '扣款机构', name: 'isInsDeduct', width: 80, align: 'center', enabledSort: false,
                    render:function(rowdata,index,value){
                        if(rowdata.isInsDeduct==0){
                            return '我司';
                        }else if(rowdata.isInsDeduct==1){
                            return '浙商';
                        }
                    }
                },
                {display: '是否能够还款', name: 'repaymentFlag', width: 80, align: 'center', enabledSort: false,
                    render:function(rowdata,index,value){
                        if(rowdata.repaymentFlag==1){
                            return '是';
                        }else{
                            return '否';
                        }
                    }
                },
                {display: '是否担保还款账单', name: 'isGuarantee', width: 80, align: 'center', enabledSort: false,
                    render:function(rowdata,index,value){
                        if(rowdata.isGuarantee==1){
                            return '是';
                        }else{
                            return '否';
                        }
                    }
                },
            ],
            usePager: false,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '300',
            heightDiff: -2,
            allowUnSelectRow: true,
            alternatingRow: false,
            delayLoad: true,
            checkbox: false
        });

        billGridLnkComp.setHeight(300);


        formLnkComp = $("#searchBarLnkComp").ligerForm({
            validate: true
        });

        $("#pageloading").hide();

        /* 查询 */
        $("#searchBtnLnkComp").click(function (event) {
            if (!formLnkComp.valid()) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
                return false; //验证不通过，不执行以下代码
            }
            formLnkComp = liger.get("searchBarLnkComp");
            var data = formLnkComp.getData();
            for (name in data) {
                billGridLnkComp.setParm(name, data[name]);
            }
            billGridLnkComp.reload();
        });

        /* 清空 */
        $("#clearBtnLnkComp").click(function (event) {
            clearLigerForm("searchBarLnkComp");
        });

    });

    //逾期明细列表
    function showDetail_grid(row, detailPanel, callback) {
        var gridBox = document.createElement('div');
        $(gridBox).css('margin', 10);
        $(detailPanel).css({
            'padding': 10,
            'box-sizing': 'border-box'
        }).append(gridBox);
        detailGrid = $(gridBox).ligerGrid({
            url: '<%=path%>/risk/rentRemind/initPaySchDList.do?paySchId=' + row.id,
            method: 'get',
            columns: [
                {display: '费用类型', name: 'feeTypCdNm', width: 120, align: 'left'},
                {display: '期次', name: 'payPd', width: 90, align: 'center'},
                {display: '应收日期', name: 'payDt', width: 90, align: 'center', render: renderDate},
                {
                    display: '应收金额', name: 'feeAmt', width: 90, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.feeAmt / 100);
                    }
                },
                {
                    display: '已付金额', name: 'paidUpAmt', width: 100, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.paidUpAmt / 100);
                    }
                },
            ],
            root: 'rows',
            hideLoadButton: true,
            width: '100%',
            height: 'auto',
            isScroll: false,
            rownumbers: true,  //显示序号
            checkbox: false,
            allowUnSelectRow: true,
            alternatingRow: false,
            onAfterShowData: callback,
            frozen: false,
            usePager: false
        });
    }

    //查询客户详情
    function showCstDtl(_cstId) {
        Add_navTab("InsPlcCstBscInfo_" + _cstId, "客户信息", '<%=path%>/customer/cstbscinfo/toCustDetailPage.do?id=' + _cstId, null);
    }

    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }
</script>

</body>
</html>
